'''
元素等待的3种方法
(1)显示等待是针对某一个元素进行相关等待判定
WebDriverWait()
(2)隐式等待不针对某个元素进行等待，全局元素等待
implicitly_wait() 默认参数的单位为秒
(3)sleep休眠方法
sleep()
'''
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC  # 起个别名
from selenium.webdriver.support.wait import WebDriverWait

from options import options

url = r'https://www.baidu.com'
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(30)  # 隐式等待，放在所有定位元素之前，单位为秒

driver.find_element(By.ID, 'kw').send_keys('abcdefg')
sleep(3)

# 显式等待————针对百度按钮
su_loc = (By.ID, 'su')
ele = WebDriverWait(driver, 30, 0.5).until(EC.visibility_of_element_located(su_loc))  # 是否可见
ele.click()
sleep(4)

driver.quit()
